//
//  ArtController.swift
//  soapp_Example
//
//  Created by zhuxietong on 2018/9/28.
//  Copyright © 2018 CocoaPods. All rights reserved.
//

import Foundation
import soapp
import Eelay
import AsyncDisplayKit


class ArtController: MoWebController{
    
    
    
    var ID:String{
        get{
            return mo.model.possible("id", default: "1")
            
        }
    }
    
    var bt = ASButtonNode()
    
    @objc func doaction() {
    }
    
    override func viewDidLoad() {
        
     
        super.viewDidLoad()
        title = mo.model["__title__","详情".loc]
        mo.detail = NSMutableDictionary()
//        mo_request_send()
        bt.ui.font(size: 12).ntitle(title: "goods").buttonColor(hex: "#888").set(radius: 4, width: nil, color: nil)
        
        bt.addTarget(self, action: #selector(doaction), forControlEvents: .touchUpInside)
        
//        if #available(iOS 11, *) {
//            bar.translatesAutoresizingMaskIntoConstraints = false
//            let guide = self.safeAreaLayoutGuide
//
//            let top = NSLayoutConstraint(item: bar, attribute: .top, relatedBy: .equal, toItem: self, attribute: .top, multiplier: 1, constant: 0)
//            var bottom = guide.bottomAnchor.constraintEqualToSystemSpacingBelow(bar.bottomAnchor, multiplier: 1.0)
//
//            var bottomHeight = TP.bottomLayoutGuide
//            if bottomHeight > 10{
//                bottomHeight = -bottomHeight/2.0 - 4
//                //                    bottomHeight = -bottomHeight
//                //                    bottomHeight = 0
//            }
//            else{
//                bottomHeight = 0
//            }
//            bottomJust = -bottomHeight
//        print("+++++iooopppp-==========")
    }
    
    override func bottomSpecGetter() -> _Spec?{
        let spec = _Spec.stack(["49","v",&-.stretch,_justfy(.center)], childs: [
            bt["36",[0,20]]
        ])
        return spec
    }
    
//    override func bottomSpecGetter() -> _Spec? {
//        print("++++++OOOOOD")
//        return _Spec.inset([], [0,20], child: bt.Spec)
//    }
    
    override open func mo_request_send() {
//        let objID = ID
//        weak var wself = self
//        loadingV.loading()
//        JoTask().post.log.log_response()._2url(.店铺详情).params(["id":objID]).json_handle { (success, msg, obj, resp) in
//            wself?.loadingV.dismiss()
//            if success{
//                if let dict = obj as? NSMutableDictionary{
//                    wself?.mo.detail = dict
//                    return
//                }
//            }
//            wself?.mo_request_alert()
//            }.run()
    }
    let bt1 = ASButtonNode()
    
//    override func botttomSpecGetter() -> _Spec {
//        return _Spec.inset([], [0,__edge], child: bt1.Spec)
//
//    }
//
    deinit {
        print("+++++++++___OOOS")
    }
    
    
    
    override open func mo_detail_reload() {
//        contentNode.setNeedsLayout()
//        contentNode.setNeedsDisplay()
//        mo.detail["link"] = "goods?id=1"
//        linker = ArtLinker(rawValue: mo.detail)
//
//        let bts = linker.actionButttons
//        //        bt1.ui.font(size: 20).buttonColor(hex: "#999").ntitle(title: "<#T##String#>")
//        bts.0?.assign(to: bt1).run()
//        bt1.ui.set(radius: 4, width: nil, color: nil)
        eeWeb.template = "服饰详情"
                let req = URLRequest(url: URL(string: "https://www.cnblogs.com/shidaying/p/3651443.html")!)
                webNode.webView.load(req)
//        self.webView.load(render: render)
    }
    
    
    
    override open func replace(_ tag: String) -> String {
        
        let list = DataNode.path(node: "list", mo.detail, value: NSMutableArray())
        
        switch tag {
        case "content":
            var content = mo.detail["content",""]
            content.replaceAll(matching: "<img(.+?)src=\"(.+?)\"(.+?)>", with: "<img src=\"$2\"/>")//去掉img style 属性
            content.replaceAll(matching: "text-indent", with: "-text-indent")//图片对其存在的显示bug
            //            content.replaceAll(matching: "margin-left:", with: "_margin-left:")//去掉img style 属性
            
            
            //            content.replaceAll(matching: "<img(.+?)style(.+?)/>", with: "<img$1style_$2/>")//去掉img style 属性
            //            content.replaceAll(matching: "<img(.+?)width(.+?)/>", with: "<img$1width_$2/>")//去掉img style 属性
            //            content.replaceAll(matching: "<img(.+?)height(.+?)/>", with: "<img$1height_$2/>")//去掉img style 属性
            
            return content
        case "cover":
            return mo.detail["thumb",""]
        case "logo":
            return mo.detail["logo",""]
            
        case "hiddenGoods":
            if list.count > 0
            {
                return "nohidden"
            }else{
                return "hidden"
            }
            
        default:
            return ""
        }
        
    }
}
